<!doctype html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>ginadmin-主页</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./js/utils.js"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script>
        // 是否开启刷新记忆tab功能
        var is_remember = false;
    </script>
</head>
<body class="index">
<!-- 顶部开始 -->
<div class="container">
    <div class="logo">
        <a href="./index.html">ginadmin-主页</a></div>
    <div class="left_open">
        <a><i title="展开左侧栏" class="iconfont">&#xe699;</i></a>
    </div>
    <ul class="layui-nav right" lay-filter="">
        <li class="layui-nav-item">
            <!--<a href="javascript:;" id="username"></a>-->
            <p id="username"></p>
            <dl class="layui-nav-child">
                <dd>
                    <a onclick="logout()">注销</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item to-index">
            <a href="/" style="display: block;">欢迎登陆</a></li>
    </ul>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<!-- 左侧菜单开始 -->
<div class="left-nav">
    <div id="side-nav">
        <ul id="nav">


        </ul>
    </div>
</div>
<!-- <div class="x-slide_left"></div> -->
<!-- 左侧菜单结束 -->
<!-- 右侧主体开始 -->
<div class="page-content">
    <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
        <ul class="layui-tab-title">
            <li class="home">
                <i class="layui-icon">&#xe68e;</i>我的桌面</li>
        </ul>
        <div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
            <dl>
                <dd data-type="this">关闭当前</dd>
                <dd data-type="other">关闭其它</dd>
                <dd data-type="all">关闭全部</dd>
            </dl>
        </div>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <iframe src='./view/welcome.html' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
            </div>
        </div>
        <div id="tab_show"></div>
    </div>
</div>
<div class="page-content-bg"></div>
<style id="theme_style"></style>
<!-- 右侧主体结束 -->
<!-- 中部结束 -->
<script>
    var attributes = {
        id: 'ID', // 对应list 数据中的ID
        parentId: 'ParentId', // 对应list 数据中的父ID
        name: 'Name', // 对应list 数据中的名称
        url:'Url',
        rootId: 0 // 自定义最外层的父ID
    };
    layui.use(['jquery'], function() {
        $("#username").text(sessionStorage.getItem('name'));
        console.log("sessionStorage.getItem('name')==>",sessionStorage.getItem('name'))
        let sessionmenu = JSON.parse(sessionStorage.getItem('menu'))
        let sessionmenutreedata = toMenuTreeData(sessionmenu,attributes)
        drewFirstLevelmenu(sessionmenutreedata)
    });

    function menutemp(title,submenu){
        let menuhtml = " <li> " +
            "<a href='javascript:;'>" +
            " <i class='iconfont left-nav-li' lay-tips='" + title + "'>&#xe6b8;</i>" +
            " <cite>" + title + "</cite>" +
            " <i class='iconfont nav_right'>&#xe697;</i>" +
            " </a> " +
            " <ul class='sub-menu'> ";

        for (var i = 0; i < submenu.length; i++) {
            let addtabhtml =  "<a onclick=xadmin.add_tab('" + submenu[i].menutitle + "','" + submenu[i].url + "')>";
            if(submenu[i].submenu != undefined && submenu[i].url == undefined){
                addtabhtml = "<a href='javascript:;'>";
            }
            menuhtml = menuhtml +  "<li>" +
                addtabhtml +
                "<i class='iconfont'>&#xe6a7;</i>" +
                "<cite>" + submenu[i].menutitle +
                "</cite>";

            menuhtml =	drawSecondLevelmenu(menuhtml,submenu[i])
            menuhtml = menuhtml + "</a></li>";

        }
        menuhtml = menuhtml + '</ul>' +
            '</li>';
        $("#nav").append(menuhtml);
    }


    function drewFirstLevelmenu(menu) {
        for (var i = 0; i < menu.length; i++) {
            menutemp(menu[i].menutitle,menu[i].submenu)
        }
    }

    function drawSecondLevelmenu(menuhtml,submenu) {

        if((submenu.url == undefined) && submenu.submenu != undefined){
            menuhtml = menuhtml + "<i class='iconfont nav_right'>&#xe697;</i></a>";
            menuhtml = menuhtml + "<ul class='sub-menu'>"
            let itemSubmenu = submenu.submenu
            for(var j=0;j<itemSubmenu.length;j++){
                let itemmenu = itemSubmenu[j]
                submenuhtml = "<li>" +  "<a onclick=xadmin.add_tab('" + itemmenu.menutitle + "','" + itemmenu.url + "')>" +
                    " <i class='iconfont'>&#xe6a7;</i>" +
                    " <cite>"+itemmenu.menutitle+"</cite></a>" +
                    "</li>";
                menuhtml = menuhtml + submenuhtml
            }
            menuhtml = menuhtml + " </ul>"
        }
        return menuhtml
    }

    function logout() {
        sessionStorage.clear()
        window.parent.location.replace("/")
    }
</script>
</body>

</html>
